@extends('admin.layout.layout', ['row' => @$page])

@section('title', @$page['title'])

@section('contain')
    <div class="container" style="padding-bottom: 20px; padding-top: 20px;">
        <div class="row" style="text-align: center;margin-bottom: 20px;margin-top: 20px;">
            <div class="col"><h2>门店质保销售分数统计</h2></div>
            <div class="col-sm-1" style="float: right;">
                <a href="/admin/stat/price"><button class="btn btn-primary">返回</button></a>
            </div>
            <div class="col-sm-1" style="float: right;">
                <button class="btn btn-primary" id="export">导出</button>
            </div>
        </div>
        <div style="width: 50%;float: left; padding: 5px 10px;">
            <div style="float: left; width: 12%;">
                <button type="button" class="btn btn-secondary" id="all_country">全国</button>
            </div>
            <div style="float: left; width: 40%;">
                <div class="input-group mb-3 custom-control-inline">
                    <div class="input-group-prepend">
                        <span class="input-group-text">省代</span>
                    </div>
                    <select class="form-control" style="width: 60%" id="distributions">
                        <option selected disabled value="">选择省代</option>
                        @if (!empty($distributions))
                            @foreach($distributions as $distribution)
                                <option value="{{ $distribution->id }}" {{ !empty($dist_id) && $dist_id == $distribution->id ? 'selected' : '' }}>{{ $distribution->abbr }}</option>
                            @endforeach
                        @endif
                    </select>
                </div>
            </div>
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 40%; margin-left:5%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">经销商级别</span>
                </div>
                <select class="form-control" style="width: 30%;" id="mdtype">
                    <option value="all">所有</option>
                    @foreach([1,2,3,4,5,0] as $v)
                        <option value="{{ $v }}" {{ $mdtype !== 'all' && $mdtype == $v ? 'selected' : '' }}>{{ ts('mdtype'.$v) }}</option>
                    @endforeach
                </select>
            </div>

        </div>
        <div style="width: 50%;float: left; padding: 5px 10px;">
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 30%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">钻石等级</span>
                </div>
                <select class="form-control" style="width: 50%;" id="zsdj">
                    <option value="all">所有</option>
                    @foreach([0,3,5] as $v)
                        <option value="{{ $v }}" {{ $zsdj !== 'all' && $zsdj == $v ? 'selected' : '' }}>{{ ts('zsdj'.$v) }}</option>
                    @endforeach
                </select>
            </div>
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 30%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">年份</span>
                </div>
                <select class="form-control" style="width: 50%;" id="year">
                    @for ($i = $start_year; $i > $start_year - 4; $i--)
                        <option value="{{ $i }}" {{ $i == $year ? 'selected' : '' }}>{{ $i }}</option>
                    @endfor
                </select>
            </div>
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 30%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">月份</span>
                </div>
                <select class="form-control" style="width: 50%;" id="month">
                    <option value="">月份总计</option>
                    @foreach($months as $key => $value)
                        <option value="{{ $key + 1 }}" {{ $month == ($key + 1) ? 'selected' : '' }}>{{ $value }}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div style="width: 50%;float: left; padding: 5px 10px;">
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 40%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">认证状态</span>
                </div>
                <select class="form-control" style="width: 50%;" id="cert_status">
                    <option value="">全部</option>
                    <option value="1" {{ $cert_status == '1' ? 'selected' : '' }}>未完成</option>
                    <option value="2" {{ $cert_status == '2' ? 'selected' : '' }}>已完成</option>
                </select>
            </div>
        </div>
        <div>
            <table class="table bt-table table-bordered table-hover">
                <thead>
                <tr class="order_column text-center">
                    <th>序列号</th>
                    <th style="width: 100px !important;word-wrap:break-word;word-break:break-all;">省份</th>
                    <th style="width: 100px !important;word-wrap:break-word;word-break:break-all;">店面名称</th>
                    <th>联系人</th>
                    <th>电话</th>
                    <th>认证日期</th>
                    <th>认证状态</th>
                    <th>钻石等级</th>
                    <th>认证费用</th>
                    <th>店面级别</th>
                    <th>MAX卷数</th>
                    <th>全车数量</th>
                    <th>任务值</th>
                    <th>质保分数</th>
                    @if (!empty($month))
                        <th>是否返点</th>
                    @endif
                </tr>
                </thead>
                <tbody>
                @foreach($list as $key=> $value)
                    <tr class="item-list">
                        <td>{{ $key + 1 }}</td>
                        <td style="width: 100px !important;word-wrap:break-word;word-break:break-all;">{{ $value->province_name ?? '' }}</td>
                        <td style="width: 100px !important;word-wrap:break-word;word-break:break-all;">{{ $value->abbr ?? '' }}</td>
                        <td>{{ $value->first_name ?? '' }}</td>
                        <td>{{ $value->phone_number ?? '' }}</td>
                        <td>{{ $value->cert_date ?? '' }}</td>
                        <td>{{ !empty($value->cert_status) ? ($value->cert_status == 1 ? '未完成' : '已完成') : '未完成' }}</td>
                        <td>{{ $value->zsdj ? ts('zsdj' . $value->zsdj) : ''}}</td>
                        <td>{{ $value->cert_price ?? '' }}</td>
                        <td>{{ ts('mdtype'. @$value->mdtype) }}</td>
                        <td>{{ $value->max_num ?? '' }}</td>
                        <td>{{ $value->car_total ?? '' }}</td>
                        <td>{{ $value->task_value ?? 0 }}</td>
                        <td>{{ $value->total ?? '' }}</td>
                        @if (!empty($month))
                            <td>{{ !empty($month) && !empty($value->total) && $value->total >= $value->task_value ? '是' : '否' }}</td>
                        @endif
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $("#year").on("change", function () {
            getRollStat();
        });
        $("#distributions").on("change", function () {
            if ($("#distributions").val() == '' || typeof $("#distributions").val() == 'undefined' || $("#distributions").val() == null) {
                return;
            }
            $("#all_country").removeClass('btn-secondary').addClass('btn-primary');
            getRollStat();
        });
        $("#month").on("change", function () {
            getRollStat();
        });
        $("#zsdj").on("change", function () {
            getRollStat();
        });
        $("#mdtype").on("change", function () {
            getRollStat();
        });
        $("#cert_status").on("change", function () {
            getRollStat();
        });

        $("#all_country").on('click', function () {
            $("#distributions").val('').trigger('change');
            $(this).removeClass('btn-primary').addClass('btn-secondary');
            getRollStat();
        });

        function getRollStat() {
            let url = '/admin/stat_compare/comparePrice?';
            let year = $("#year").val();
            let dist_id = $("#distributions").val();
            let month = $("#month").val();
            let mdtype = $("#mdtype").val();
            let zsdj = $("#zsdj").val();
            let cert_status = $("#cert_status").val();

            if (year != '') {
                url += 'year=' + year;
            }
            if (month != '') {
                url += '&month=' + month;
            }
            if (cert_status != '') {
                url += '&cert_status=' + cert_status;
            }
            if (dist_id != '' && typeof dist_id != 'undefined' && dist_id != null) {
                url += '&dist_id=' + dist_id;
            }
            url += '&zsdj=' + zsdj;
            url += '&mdtype=' + mdtype;

            if (url == '/admin/stat_compare/comparePrice?') {
                return;
            }

            location.href = url;
        }

        $("#export").on('click', function () {
            let url = '/admin/stat_compare/export?';
            let year = $("#year").val();
            let dist_id = $("#distributions").val();
            let month = $("#month").val();
            let zsdj = $("#zsdj").val();
            let mdtype = $("#mdtype").val();
            let cert_status = $("#cert_status").val();
            if (year != '') {
                url += 'year=' + year;
            }
            if (month != '') {
                url += '&month=' + month;
            }
            if (cert_status != '') {
                url += '&cert_status=' + cert_status;
            }
            if (dist_id != '' && typeof dist_id != 'undefined' && dist_id != null) {
                url += '&dist_id=' + dist_id;
            }
            if (zsdj != '') {
                url += '&zsdj=' + zsdj;
            }
            if (zsdj != '') {
                url += '&mdtype=' + mdtype;
            }

            location.href = url;
        });

    </script>
@endsection
